package prop;

import bbcom.PropertiesType;
import bbcom.interfaces.IPropertiesParser;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.impl.values.XmlAnyTypeImpl;

/**
 * Created by Thanh-Trung Pham.
 */
public class PropertiesParser implements IPropertiesParser {
    @Override
    public String getProperty(PropertiesType properties, String propertyName) {
        if (properties == null) {
            return null;
        }

        XmlObject[] oXmlObjects = properties.selectPath("$this/@"+propertyName);

        if (oXmlObjects == null || oXmlObjects.length == 0) {
            return null;
        }

        return ((XmlAnyTypeImpl) oXmlObjects[0]).getStringValue();
    }

    @Override
    public String getHost(PropertiesType properties) {
        return getProperty(properties, "host");
    }
}
